//
//  CompareAgesViewController.m
//  Astro
//
//  Created by ACER on 11/29/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "CompareAgesViewController.h"
#import "AstroAppDelegate.h"
#import "VCResult.h"
#import "VCDataInput.h"

@implementation CompareAgesViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

//===========>>>
#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	appDelegate = (AstroAppDelegate*)[[UIApplication sharedApplication] delegate];
	
    // Do any additional setup after loading the view from its nib.
}
- (void) didRecieveDateFromVCDateInput:(NSString*)outputDate andDateString:(NSString*)_dateStr{
	NSLog(@"Date: %@   -  %@", outputDate, _dateStr);
	
	if(textIsEdit == 1){
		textDateBirdth.text = [NSString stringWithFormat:@"%@", _dateStr];
		dateBirdth = [outputDate intValue];
	}
	else if(textIsEdit == 2) {
		textHourBirdth.text = [NSString stringWithFormat:@"%@", _dateStr];
		hourBirdth = [outputDate intValue];
	}
}

- (void) didCancelVCDateInput{
	NSLog(@"Cancel");
	[appDelegate.dateInput.view removeFromSuperview];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
	if (textField.tag == 0){
		textIsEdit = 0;
		
		return YES;
	}else if (textField.tag == 1){
		textIsEdit = 1;
		[self.view addSubview:appDelegate.dateInput.view];
		[appDelegate.dateInput setDatePickerMode:DatePickerModeDate];
	}
	else if (textField.tag == 2) {
		textIsEdit = 2;
		[self.view addSubview:appDelegate.dateInput.view];
		[appDelegate.dateInput setDatePickerMode:DatePickerModeTime];
	}
	
	return NO;
}



- (void) viewWillAppear:(BOOL)animated{
	[appDelegate.dateInput setDelegate:self];  
	[appDelegate.dateInput setDatePickerMode:DatePickerModeDate];
	
}
//<<<===========


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

//============
-(IBAction)clickResultBtn {
	VCResult *resultVC = [[VCResult alloc] initWithNibName:@"VCResult" bundle:nil];
	NSString *resultCommentary;
	[self.navigationController pushViewController:resultVC animated:YES];
	resultCommentary = @"comentary";
	resultVC.textResult.text = resultCommentary;
	[resultVC.imgBg setImage:[UIImage imageNamed:@"Common.BackgroundPhuongDong.png"]];
}




@end
